package com.dhcc.sdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.busi.entity.SdcBusiContraindicationHisEntity;
import com.dhcc.sdc.busi.service.ISdcBusiContraindicationHisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 禁忌症临床评估日志
 * 
 * @ClassName: SdcBusiContraindicationHisController
 * @Description: TODO
 * @author sunyingjie
 * @date 2022-09-20 14:17:04
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdcbusicontraindicationhis")
public class SdcBusiContraindicationHisController extends BaseController {

	private String PREFIX = "/backend/sdc/sdcbusicontraindicationhis/";

	@Autowired
	private ISdcBusiContraindicationHisService sdcBusiContraindicationHisService;
	

    /**
     * 跳转到禁忌症临床评估日志列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdcbusicontraindicationhis.html";
    }
	
    /**
     * 跳转到新增禁忌症临床评估日志
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdcbusicontraindicationhis_add.html";
    }
	
	/**
     * 跳转到修改禁忌症临床评估日志
     */
    @RequestMapping("/to_update/{sdcBusiContraindicationHisId}")
    public String toUpdate(@PathVariable Long sdcBusiContraindicationHisId, Model model) {
        SdcBusiContraindicationHisEntity sdcBusiContraindicationHis = this.sdcBusiContraindicationHisService.selectById(sdcBusiContraindicationHisId);
        model.addAttribute("sdcBusiContraindicationHis",sdcBusiContraindicationHis);
        return PREFIX + "sdcbusicontraindicationhis_edit.html";
    }

    /**
     * 获取禁忌症临床评估日志列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcBusiContraindicationHisEntity> page = new PageFactory<SdcBusiContraindicationHisEntity>().defaultPage();
        List<SdcBusiContraindicationHisEntity> result = this.sdcBusiContraindicationHisService.page(page,params);
        page.setRecords((List<SdcBusiContraindicationHisEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增禁忌症临床评估日志
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcBusiContraindicationHisEntity sdcBusiContraindicationHis) {
        if (CommonUtil.isOneEmpty(sdcBusiContraindicationHis)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcBusiContraindicationHis.insert();
        return R.ok();
    }

    /**
     * 删除禁忌症临床评估日志
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcBusiContraindicationHisId) {
	
        this.sdcBusiContraindicationHisService.deleteById(sdcBusiContraindicationHisId);

        return R.ok();
    }

    /**
     * 修改禁忌症临床评估日志
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcBusiContraindicationHisEntity sdcBusiContraindicationHis) {
        if (CommonUtil.isOneEmpty(sdcBusiContraindicationHis)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcBusiContraindicationHisEntity old = this.sdcBusiContraindicationHisService.selectById(sdcBusiContraindicationHis.getId());

        old.setEpisodeId(sdcBusiContraindicationHis.getEpisodeId());
        old.setContraindicationId(sdcBusiContraindicationHis.getContraindicationId());
        old.setItemIds(sdcBusiContraindicationHis.getItemIds());
        old.setResult(sdcBusiContraindicationHis.getResult());
        old.setEvalDocId(sdcBusiContraindicationHis.getEvalDocId());
        old.setEvalDocName(sdcBusiContraindicationHis.getEvalDocName());
        old.setEvalDate(sdcBusiContraindicationHis.getEvalDate());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
